from django import template
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode


register = template.Library()

def formEnvia(carrinho):

    #aqui sera feito o tratamento para gerar o carrinho
    produtos = {}
    for p in carrinho:
        produtos[str(p.id)] = p

    from django.conf import settings
    return {'MEDIA_URL': settings.MEDIA_URL}

register.inclusion_tag('pagamento_digital/template_form.html')(formEnvia)


'''
def breadcumbs(item_ativo, request, quem_sou):
    from django.core.urlresolvers import reverse
    
    show_breads = (item_ativo == 'institucional')
    show_breads |= (item_ativo == 'noticias')
    show_breads |= (item_ativo == 'acervo')
    show_breads |= (item_ativo == 'exposicoes')
    show_breads |= (item_ativo == 'ensino')
    show_breads |= (item_ativo == 'pesquisa')
    show_breads |= (item_ativo == 'publicacoes')
    show_breads |= (item_ativo == 'biblioteca')
    show_breads |= (quem_sou == 'Busca Google')

    
    item = {'institucional' : {'url' : reverse('institucional'), 'label': 'Institucional'},
            'noticias'      : {'url' : reverse('noticias'), 'label': 'Not&iacute;cias'},
            'acervo'        : {'url' : reverse('acervo'), 'label': 'Acervo'},
            'exposicoes'    : {'url' : reverse('exposicoes'), 'label': 'Exposicoes'},
            'ensino'        : {'url' : reverse('ensino'), 'label': 'Ensino'},
            'pesquisa'      : {'url' : reverse('pesquisa'), 'label': 'Pesquisa'},
            'publicacoes'   : {'url' : reverse('publicacoes'), 'label': 'Publicacoes'},
            'biblioteca'    : {'url' : reverse('biblioteca'), 'label': 'Biblioteca'} }
    try:
        bread = item[item_ativo]
    except:
        bread = False
    extra = ( quem_sou != None and quem_sou != item_ativo and quem_sou != '*')

    from django.conf import settings
    return { 'MEDIA_URL': settings.MEDIA_URL, 'request': request, 'view_atual': item_ativo, 
             'show_breads':show_breads, 'bread':bread, 'extra':extra, 'quem_sou': quem_sou }

register.inclusion_tag('uteis/breadcumbs.html')(breadcumbs)



@register.filter
def unescape(value):
    aux = force_unicode(value).replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&#39;', "'").replace('&amp;', '&')
    return mark_safe(aux)


@register.filter
def clean_video_url(value):
    temp = str(value)

    try:
        temp = 'http:/'+temp.split('static_media')[1]
    except:
        pass

    #try:
    #    temp = temp.split('&')[0]
    #except:
    #    pass

    return temp



def video(url, height, width):
    from mae.functions import video_function
    html = video_function(url, height, width)

    from django.conf import settings
    return {'MEDIA_URL': settings.MEDIA_URL, 'html': html}

register.inclusion_tag('uteis/video.html')(video)





class MyNode(template.Node):
    def __init__(self, html):
        self.html = html
    def render(self, context):
        return self.html



def google_search():

    from django.conf import settings
    return {'MEDIA_URL': settings.MEDIA_URL}

register.inclusion_tag('uteis/google_search.html')(google_search)
'''
